<?php
include_once "xAP-functions/webincludes.php";

echo webpageheader("xAP Intranets");

$sql="select * from xAP_Intranet where active=1 
and updated>'".date("Y-m-d H:i:s",time()-60*15)."'
and source<>'".$config["xapsource"]."'";

$intranets=dbquery($sql);



echo "<div class='headerwrapper'>
<table><TR>";
foreach($intranets as $row){
	echo "<TD><center><a href=\"".$row["URL"]."\"><img src=\"".$row["Icon"]."\" border=0></a><BR><b>".$row["iName"]."</b></center></td>";
}
echo "</TR></table>
</div>";

?>

<table class='columnwrapper'><TR>
<td class='homecolumn'><div id='column1' class='homecolumndiv'></div></td>
<td class='homecolumn'><div id='column2' class='homecolumndiv'></div></td>
<td class='homecolumn'><div id='column3' class='homecolumndiv'></div></td>
<td class='widgetaddwrapper'><div id='sidebar'></div></td>
</tr>
</table>
<script>

$(document).ready(function(){


$("#column1").sortable({connectWith: ["#column2,#column3"]});
$("#column2").sortable({connectWith: ["#column1,#column3"]});
$("#column3").sortable({connectWith: ["#column2,#column1"]});
	$("#sidebar").sortable({connectWith: ["#column1,#column2,#column3"],update : function(e,ui){
		SaveLocation();
		}
	});
	$("#sidebar").sortable("disable");
GetWidgets();
//setInterval("GetWidgets()",60000);
});

function GetWidgets(){
			
				
				$.get("layoutcolumn.php?id=1",function(data){
					$('#column1').html(data);
				});	
				$.get("layoutcolumn.php?id=2",function(data){
					$('#column2').html(data);
				});	
				$.get("layoutcolumn.php?id=3",function(data){
					$('#column3').html(data);
				});	
				
				
}
function SaveLocation(){
	cols="";
	$('#saveicon').attr("src","/xAP-Layout/<?=$config["theme"]?>/images/throbber.gif");
	$('#sidebar').html("");
	for(vl=1;vl<4;vl++)
	{
	$('#column' + vl + ' .widgetwrapper').each(function(){
		cols += "Col" + vl + "[]=" + $(this).attr("id") + "&";
		});
	}
	$.get("layout_save.php",cols,function(data){
		$('#saveicon').attr("src","/xAP-Layout/<?=$config["theme"]?>/images/save.png");
		GetWidgets();
		
	});
	
}
function AddNew(){
	$('#sidebar').load("layout_add.php");
	$("#sidebar").sortable("enable");
}
function WidgetEdit(id){
	$('#sidebar').load("layout_config.php?id=" + id);
	$("#sidebar").sortable("disable");
}
function AddClose(){
	$('#sidebar').html("");
	$("#sidebar").sortable("disable");
}
function WidgetAddClose(id){
	$(".widgetwrapper[seed='" + id + "']").remove();
}
function WidgetSave(){
	var str = $("form").serialize();
	$.post("layout_config_save.php",str,function(data){
		if(data=='1'){
			$('#sidebar').html("");
			GetWidgets();
		}
	});
}
</script>
<a href='#' onclick="GetWidgets()"><img id='reloadicon' src='/xAP-Layout/<?=$config["theme"]?>/images/reload.png'></a>
<a href='#' onclick="SaveLocation()"><img id='saveicon' src='/xAP-Layout/<?=$config["theme"]?>/images/save.png'></a>
<a href='#' onclick="AddNew()"><img id='saveicon' src='/xAP-Layout/<?=$config["theme"]?>/images/add.png'></a>
<?php
echo webpagefooter();
?>